//
//  oldMessageSender.m
//  laonianbang
//
//  Created by 勇拓 李 on 17/10/30.
//  Copyright © 2017年 zaiyou. All rights reserved.
//

#import "oldMessageSender.h"
#import "oldTools.h"

@implementation oldMessageSender

NSString *GetMessageTypeOfSender(oldMessageType status) {
    switch (status) {
        case orderCreate:
            return @"old_message_create";
        case orderStart:
            return @"old_message_start";
        case orderEnd:
            return @"old_message_end";
        case orderFail:
            return @"old_message_fail";
        case orderReject:
            return @"old_message_reject";
        case orderCancel:
            return @"old_message_cancel";
        case userServerApprovePass:
            return @"old_message_reject";
        case userServerApproveFail:
            return @"old_message_cancel";
        case newMessage:
            return @"old_new_momentmessage";
        case paySuccess:
            return @"pay_success";
        case payFail:
            return @"pay_failed";
        default:
            return @"old_message_all";
    }
}

- (void)sendMessage:(id)message type:(oldMessageType)type
{
    [[NSNotificationCenter defaultCenter] postNotificationName:GetMessageTypeOfSender(type) object:message];
}

- (void)receiveMessage:(NSString *)message
{
    NSDictionary *dic = [oldTools dictionaryWithJsonString:message];
    NSInteger type = [dic[@"code"] integerValue];
    
    [self sendMessage:nil type:orderAll];
    
    if (type ==  orderFail || type ==  orderReject) {
        [self sendMessage:dic[@"message"] type:type];
    }
    else
    {
        [self sendMessage:dic[@"data"] type:type];
    }
}

@end
